<template>
    <!-- 入库 -->
    <el-dialog title="入库" :visible.sync="dialogVisible" width="30%" :before-close="handleClose">
        <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="auto">
            <c-form-template lable="仓库基础信息" label-position="left">
                <el-col :span="20" class="mt-lg">
                    <el-form-item label="GPS绑定" prop="gps">
                        <el-input v-model="ruleForm.gps" placeholder="请输入GPS"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="24" v-if="dialogVisible">
                    <el-form-item label="上传车辆照片" prop="pathPhoto">
                        <c-upload @change="$refs.ruleForm.validateField('pathPhoto')" v-model="ruleForm.files" />
                    </el-form-item>
                </el-col>
            </c-form-template>
        </el-form>
        <div>
            <el-row :gutter="24" class="">
                <el-col :span="24" class="detailsTitle mb-0">仓库基础信息</el-col>

                <el-col :span="12" class="mt-lg">
                    仓库名称：{{storeInfo.name}}
                </el-col>
                <el-col :span="12" class="mt-lg">
                    联系方式：{{storeInfo.contactPhone}}
                </el-col>
                <el-col :span="24" class="mt-lg">
                    仓库地址：{{storeInfo.addressCountry}}-{{storeInfo.addressCity}}-{{storeInfo.addressDetails}}
                </el-col>
                <el-col :span="8" class="mt-lg">
                    仓储费：{{storeInfo.charge}}元
                </el-col>
                <el-col :span="8" class="mt-lg">
                    入库费：{{storeInfo.feeIn}}元
                </el-col>
                <el-col :span="8" class="mt-lg">
                    出库费：{{storeInfo.feeOut}}元
                </el-col>
            </el-row>
        </div>
        <span slot="footer">
            <el-button :loading="loading" @click="handleClose">取 消</el-button>
            <el-button :loading="loading" type="primary" @click="handleSubmit">确 定</el-button>
        </span>
    </el-dialog>
</template>
<script>
export default {
    data () {
        return {
            dialogVisible: false,
            options: [],
            loading: false,
            storeInfo: {},
            ruleForm: {
                files: [],
            },
            rules: {
                gps: [{ required: true, message: "请输入GPS", trigger: "blur" }],
                files: [
                    {
                        type: "array",
                        required: true,
                        message: "请上传车辆照片",
                        trigger: "change",
                    },
                ],
            },
        };
    },
    mounted () {
    },
    methods: {

        handleSubmit () {
            this.$refs.ruleForm.validate((valid) => {
                if (valid) {
                    this.$confirm("是否确认此操作?", "提示", {
                        confirmButtonText: "确定",
                        cancelButtonText: "取消",
                        type: "warning",
                    }).then(() => {
                        this.loading = true;
                        const url = "/storeCar/storeIn";
                        // const data = JSON.parse(JSON.stringify(this.ruleForm));
                        const data = [this.ruleForm];
                        this.$post({ url, data }).then(
                            () => {
                                this.$message.success("操作成功");
                                this.handleClose();
                                this.$parent.$parent.tableList();
                                this.loading = false;
                            },
                            () => {
                                this.loading = false;
                            }
                        );
                    });
                }
            });
        },
        handleOpen (item, storeInfo) {
            console.log(item, storeInfo);
            if (item && item.id) {
                this.ruleForm.id = item.id;
                this.storeInfo = storeInfo;
            }
            this.dialogVisible = true;
        },
        handleClose () {
            this.ruleForm = {
                pathPhoto: [],
                pathProcedure: [],
            };
            this.$refs.ruleForm.resetFields();
            this.dialogVisible = false;
        },
    },
};
</script>
